templateViewInit = ()=>{
    searchFormInfo();

    // 已知数据渲染
    var inst = table.render({
        elem: '#definition-list',
        id:'definition-list-id',
        height: '#content-body-150',
        url: top.tools.getBaseUrl()+'/activiti/getPage',
        method: 'post',
        headers:{
            'Access-Token':top.tools.cookie.token(),
            'Content-Type':'application/json',
        },
        toolbar: '#dictToolbar',
        defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
            title: '提示',
            layEvent: 'LAYTABLE_TIPS',
            icon: 'layui-icon-tips',
            onClick: function (obj) { // 2.9.12+
                layer.alert('自定义工具栏图标按钮');
            }
        }],
        cols: [
            [
                {type: 'checkbox', width: 50},
                {type: 'numbers', title: '序号', align: 'center', width: 80},
                {field: 'key', title: 'KEY', align: 'left',width: 120},
                {field: 'name', title: '模型名称', align: 'left', minWidth: 200},
                {field: 'version', title: '版本', align: 'center',width: 60},
                {field: 'description', title: '流程描述', align: 'left',minWidth: 100},
                // {field: 'category', title: '所属分类', align: 'left',minWidth: 100},
                // {field: 'deploymentId', title: '部署ID', align: 'left',minWidth: 100},
                {field: 'resourceName', title: '资源路径', align: 'left',minWidth: 100},
                {field: 'suspended', title: '流程定义状态', align: 'left',width: 120,templet:function (d){
                        let c = d.suspended==='true' ? 'notify-msg-error':'notify-msg-success';
                        return '<span class="notify-msg '+c+'" style="padding: 0 15px;justify-content: center;">'+d.suspendedName+'</span>';
                    }},
                {fixed: 'right', title: '操作', align: 'center',  width: 300, toolbar: '#barDemo'}
            ]
        ],
        parseData: dataToFormat,
        data:[
            {id:1,name:'用户性别',type:'system_user_sex',status:'0',remark:'',createTime:'2021-01-05 17:03:48'}
        ],
        //skin: 'line', // 表格风格
        //even: true,
        page: true, // 是否显示分页
        limits: [15, 20, 30,50],
        limit: 15, // 每页默认显示的数量
        done: function (res, curr, count) {
            $(".layui-table th[data-field=" + 0 + "] .layui-table-cell").html("");
        }
    });
    // 工具栏事件
    table.on('toolbar(definition-list)', function (obj) {
        var id = obj.config.id;
        var checkRow = table.checkStatus(id);
        if (checkRow.data.length<=0 && obj.event !== 'add'){
            layer.msg("请选择数据！");
            return
        }
        var data = checkRow.data;
        if (obj.event === 'add') {
            openDefinition({},function (bpmnModeler,options){
                // bpmnModeler.importXML("<?xml version=\"1.0\" encoding=\"UTF-8\"?><definitions  xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\" xmlns:omgdc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:omgdi=\"http://www.omg.org/spec/DD/20100524/DI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:activiti=\"http://activiti.org/bpmn\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.activiti.org/processdef\"><process  id=\"oa-leave\" name=\"oa-leave\" isExecutable=\"true\"><startEvent  id=\"sid-ba3f982e-9b18-4631-a24e-6e3e625d87b3\" name=\"开始\"><outgoing>Flow_1novv45</outgoing></startEvent><endEvent  id=\"sid-8cf08e72-e109-4fac-a2ac-359e212eda78\" name=\"结束\"><incoming>Flow_1novv45</incoming></endEvent><sequenceFlow  id=\"Flow_1novv45\" sourceRef=\"sid-ba3f982e-9b18-4631-a24e-6e3e625d87b3\" targetRef=\"sid-8cf08e72-e109-4fac-a2ac-359e212eda78\" /></process><bpmndi:BPMNDiagram id=\"BPMNDiagram_oa-leave\"><bpmndi:BPMNPlane id=\"BPMNPlane_oa-leave\" bpmnElement=\"oa-leave\"><bpmndi:BPMNShape id=\"shape-d6ce8392-4da9-44a7-aad0-735f74a79162\" bpmnElement=\"sid-ba3f982e-9b18-4631-a24e-6e3e625d87b3\"><omgdc:Bounds x=\"-70\" y=\"-60\" width=\"30\" height=\"30\" /></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"shape-b3aa73d9-f03c-476f-bcbf-3a1bc7b5fccd\" bpmnElement=\"sid-8cf08e72-e109-4fac-a2ac-359e212eda78\"><omgdc:Bounds x=\"175\" y=\"-60\" width=\"30\" height=\"30\" /><bpmndi:BPMNLabel><omgdc:Bounds x=\"179\" y=\"-30\" width=\"22\" height=\"14\" /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNEdge id=\"Flow_1novv45_di\" bpmnElement=\"Flow_1novv45\"><omgdi:waypoint x=\"-40\" y=\"-45\" /><omgdi:waypoint x=\"175\" y=\"-45\" /></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></definitions>")
            })
        } else if (obj.event === 'apply') {

        } else  if (obj.event === 'renew') {

        }
    });
    // 触发单元格工具事件
    table.on('tool(definition-list)', function (obj) { // 双击 toolDouble
        var data = obj.data; // 获得当前行数据
        if (obj.event === 'view') {
            openDefinition({minimapOpen:false,panel:false,extensions:false,addCustomButton: []},function (bpmnModeler,options){
                top.API.activiti().edit({deploymentId:data.deploymentId,resourceName:data.resourceName}, (res)=>{
                    // 渲染流程图
                    bpmnModeler.importXML(top.ProcessDefinition().reformXML(res.data))
                })
            })
        }else if (obj.event === 'edit') {
            openDefinition({},function (bpmnModeler,options){
                top.API.activiti().edit({deploymentId:data.deploymentId,resourceName:data.resourceName}, (res)=>{
                    // 渲染流程图
                    bpmnModeler.importXML(top.ProcessDefinition().reformXML(res.data))
                })
            })
        }else if (obj.event === 'del') {
            openConfirm(()=>{
                top.API.activiti().deleteById({deploymentId:data.deploymentId,id:data.id}, (res)=>{
                    reloadTable()
                })
            });
        }else if (obj.event ==='suspended'){
            let suspended = data.suspended;
            let suspendDefinition = {
                id:data.id,
                activateProcessInstances:true
            }
            if (suspended == 'false'){
                top.API.activiti().suspend(suspendDefinition, (res)=>{
                    reloadTable()
                })
            }else {
                top.API.activiti().activate(suspendDefinition, (res)=>{
                    reloadTable()
                })
            }
        }else if (obj.event === 'startProcess'){
            top.API.activiti().startProcess({ id:data.id}, (res)=>{

            })
        }
    });


    queryButton('definition-list-id');
    formReset();

    function openDefinition(options,callback){
        top.API.common().loadPage('page/from-component/process-definition.html',function (response){
            let addCustomButton = options.addCustomButton;
            openForm({
                title:"流程定义",
                btn:-1,
                area:['99%','99%'],
                before:(index,layero,that,isEdit)=>{
                    let intervalId = setInterval(()=>{
                        if (top.ProcessDefinition){
                            clearInterval(intervalId);
                            top.ProcessDefinition().init(options,callback)
                        }
                    },500)
                },
                cancel:(index,layero,that) => {
                    if (!addCustomButton){
                        table.reloadData('definition-list-id', {
                            where: {}, // 数据异步请求时携带的字段集 --- 属性设置有效，因属于数据相关属性
                            scrollPos: true, // 设定重载数据或切换分页时的滚动条的位置状态 --- 属性设置有效
                            page: {
                                curr: inst.config.page.curr,
                                limit: inst.config.page.limit
                            }
                        });
                    }

                    layer.close(index);
                }
            },'',response)
        })
    }

    function reloadTable(){
        table.reloadData('definition-list-id', {
            where: {}, // 数据异步请求时携带的字段集 --- 属性设置有效，因属于数据相关属性
            scrollPos: true, // 设定重载数据或切换分页时的滚动条的位置状态 --- 属性设置有效
            page: {
                curr: inst.config.page.curr,
                limit: inst.config.page.limit
            }
        })
    }
}
